package main

import "fmt"

type Course struct {
	name  string
	price int
	url   string
}
type Printer interface {
	printInfo() string
}

func (c Course) printInfo() string {
	return "课程信息"
}

func myprint(i interface{}) {
	switch v := i.(type) {
	case string:
		fmt.Printf("%s,字符串\n", v)
	case int:
		fmt.Printf("%d,整数\n", v)

	}
	//if v, ok := i.(int); ok {
	//	fmt.Printf("%d,整数\n", v)
	//}
	//if s, ok := i.(string); ok {
	//	fmt.Printf("%s,字符串\n", s)
	//}
}

func main() {
	//空接口
	var i interface{} //空接口
	i = Course{}
	fmt.Println(i)
	i = 10
	myprint(i)
	i = "sunck"
	myprint(i)
	i = []string{"django", "python"}
	myprint(i)
	fmt.Println(i)
	//空接口的第一个用途 可以把任何类型都赋值给空接口变量
	//2.参数传递
	//3.空接口可以作为map的值
	var teacherInfo = make(map[string]interface{})
	teacherInfo["name"] = "sunck"
	teacherInfo["age"] = 18
	teacherInfo["weight"] = 75.2
	teacherInfo["courses"] = []string{"django", "python"}
	fmt.Printf("%v", teacherInfo)
	//类型断言
	//接口的一个坑
	//c:=&Course{}

}
